﻿using DeepEarth.Map.Core;
using System.Collections.Generic;
using System;
using System.Linq;
using DeepEarth.Map.Core.Tiling;
namespace DeepEarth.Map.TileSources
{
    public class NearMapTileSourceFactory : BaseTileSourceFactory
    {
        public static readonly MapMode PhotoMap = new MapMode("nearMap", "Vert", "PhotoMap", "Photo Map", /*Order*/0, /*isOverlayMapMode*/false, /*hasLabels*/false, /*hasDates*/true);
        public static readonly MapMode StreetMap = new MapMode("nearMap", "Map_", "StreetMap", "Street Map", 0);
        public static readonly MapMode StreetMapOverlay = new MapMode("nearMap", "MapT", "StreetMapOverlay", "Street Map", 2, true, true, false);
        public static readonly MapMode Terrain = new MapMode("nearMap", "Dem_", "Terrain", "Terrain", 1, false, false, false);

        private static readonly MapMode[] _availableModes = new[] { PhotoMap, StreetMap, StreetMapOverlay, Terrain };
        public override IList<MapMode> AvailableModes { get { return _availableModes; } }

		private static readonly NearMapTileSource StreetsTileSource = new NearMapTileSource(StreetMap);
		private static readonly NearMapTileSource PhotoMapTileSource = new NearMapTileSource(PhotoMap);
		private static readonly NearMapTileSource TerrainTileSource = new NearMapTileSource(Terrain);
		private static readonly NearMapTileSource StreetMapOverlayTileSource = new NearMapTileSource(StreetMapOverlay);

        public static bool IsValidMode(MapMode mode)
		{
			return _availableModes.Contains(mode);
		}

        public static void ValidateMode(MapMode mode)
		{
			if (!IsValidMode(mode))
				throw new ArgumentOutOfRangeException(String.Format("Map mode '{0}:{1}' is not valid for the NearMap provider",
				                                                    mode.ProviderKey,
				                                                    mode.Identifier));
		}

        public override BaseTileSource CreateTileSource(MapMode mode)
		{
			mode = ValidateAndCoerceMapMode(mode);

			if (mode == PhotoMap)			return PhotoMapTileSource;
			if (mode == StreetMap)			return StreetsTileSource;
			if (mode == StreetMapOverlay)	return StreetMapOverlayTileSource;
			if (mode == Terrain)			return TerrainTileSource;

			return new NearMapTileSource(mode);
		}
    }
}
